home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / SAT 2.3.8 / Demos / StepPlatform Demo ƒ / sPlatform.c < prev    next >
Text File  |  1996-05-11  |  2KB  |  101 lines

  1. /* Platform sprite, experimental faceless sprite */
  2.  
  3. #include "SAT.h"
  4. #include "myPlatform.h"
  5.  
  6. void InitPlatform()
  7. {
  8. /* nada*/
  9. }
  10.  
  11. pascal void SetupPlatform(SpritePtr me)
  12. {
  13.     Rect            r;
  14.     PolyHandle    pol;
  15.     
  16.     me->task = &HandlePlatform;
  17.     me->hitTask = (void *)&HitPlatform;
  18.  
  19.     me->face = nil; /* = faceless! */
  20.     SetRect(&(me->hotRect), 0, 0, 100, 16);
  21.     r = me->hotRect;
  22.     OffsetRect(&r, me->position.h, me->position.v);
  23.     SATSetPortBackScreen();
  24.     ForeColor(cyanColor);
  25.     FillRect(&r, &qd.dkGray);
  26.  
  27.     pol = OpenPoly();
  28.     MoveTo(r.left, r.top);
  29.     LineTo(r.left + 5, r.top - 5);
  30.     LineTo(r.right + 5, r.top - 5);
  31.     LineTo(r.right, r.top);
  32.     LineTo(r.left, r.top);
  33.     LineTo(r.right, r.top);
  34.  
  35.     LineTo(r.right, r.bottom);
  36.     LineTo(r.right + 5, r.bottom - 5);
  37.     LineTo(r.right + 5, r.top - 5);
  38.     LineTo(r.right, r.top);
  39.  
  40.     ClosePoly();
  41.     ErasePoly(pol);
  42.     FramePoly(pol);
  43.     KillPoly(pol);
  44.  
  45.     r.top = r.top - 5;
  46.     r.right = r.right + 5;
  47.     SATBackChanged(&r); /* Tell SAT to draw it when appropriate */
  48.  
  49.     me->layer = -me->position.v;
  50. }
  51.  
  52. pascal void HandlePlatform(SpritePtr me)
  53. {
  54.     /*me->face = nil;*/ 
  55. }
  56.  
  57. pascal void HitPlatform(SpritePtr me, PlSpritePtr him)
  58. {
  59.     int    mini, i, min;
  60.     int    diff[5];
  61.     
  62.     if (him->task == (void *)HandlePlayerSprite){
  63.         diff[1] = -me->hotRect2.top + (him->hotRect2.bottom);        /* TtoB */
  64.         diff[2] = -him->hotRect2.top + (me->hotRect2.bottom);         /* BtoT */
  65.         diff[3] = -me->hotRect2.left + (him->hotRect2.right);        /* LtoR */
  66.         diff[4] = -him->hotRect2.left + (me->hotRect2.right);        /* RtoL */
  67.         mini = 0;
  68.         min = 10000;
  69.         for(i = 1; i <= 4 ; i++){
  70.             if(min > diff[i]){
  71.                 min = diff[i];
  72.                 mini = i;
  73.             } /* if */
  74.         }
  75.         switch(mini){
  76.             case 1: /*floor*/
  77.                     him->action = Stand;
  78.                     him->position.v = him->position.v - diff[1] + 1; 
  79.                     if(him->speed.v > 0)
  80.                         him->speed.v = 0;
  81.                     him->speed.h = 0;
  82.                     break;
  83.             case 2: /* ceiling */
  84.                     him->position.v = him->position.v + diff[2] + 1;
  85.                     if(him->speed.v < 0)
  86.                         him->speed.v = -him->speed.v;
  87.                     break;
  88.             case 3: /*left*/
  89.                     him->position.h = him->position.h - diff[3] - 1;
  90.                                     if(him->speed.h > 0)
  91.                         him->speed.h = -him->speed.h;
  92.                     break;
  93.             case 4: /*right*/
  94.                     him->position.h = him->position.h + diff[4] + 1;
  95.                     if(him->speed.h < 0)
  96.                         him->speed.h = -him->speed.h;
  97.                     break;
  98.         } /* switch */
  99.     }
  100. }
  101.